package com.yanqu.road.server.cmd.activity.unionchest;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.UnionChestProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.activity.unionchest.CrossUnionChestMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.utils.YanQuMessageUtils;


@Cmd(code = CrossProtocol.C2_UNIONCHEST_SYNC_USER_DATA, desc = "同步玩家数据")
public class CrossUnionChestSyncUserDataCmd extends CrossCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {

        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        UnionChestProto.CrossUnionChestSyncUserReqMsg reqMsg = UnionChestProto.CrossUnionChestSyncUserReqMsg.parseFrom(packet.getBytes());
        UnionChestProto.UnionChestUserSyncMsg.Builder syncMsg = CrossUnionChestMgr.getUserSyncMsg(reqMsg.getActivityId(), packet.getPlayerId(), reqMsg.getUnionId());
        if (reqMsg.getReqType() == ClientProtocol.U_UNIONCHEST_USER_DATA_REQ) {
            UnionChestProto.UnionChestUserRespMsg.Builder builder = UnionChestProto.UnionChestUserRespMsg.newBuilder();
            builder.setUserData(syncMsg);
            YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(reqMsg.getReqType(), builder);
            MessageHelper.sendPacket(serverId, packet.getPlayerId(), pbMsg);
        } else {
            YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(reqMsg.getReqType(), syncMsg);
            MessageHelper.sendPacket(serverId, packet.getPlayerId(), pbMsg);
        }
    }

    @Override
    public void sendData() {
    }
}
